package org.martin.office;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipException;

import freemarker.template.TemplateException;

/**
 * Hello world!
 *
 */
public class App {
  public static void main(String[] args) throws IOException, TemplateException {
    //设置docx的模板路径 和文件名  
    final String docxTemplate = "template/test.docx";
    try {
      for(int i=0;i<10;i++) {
        new Thread(new Runnable() {
          
          @Override
          public void run() {
            File documentFile = null;
            try {
              Map<String, Object> map = new HashMap<String, Object>();
              map.put("title", Thread.currentThread().getId());
              map.put("content", "测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容");
              FreemarkerHandle handle = new FreemarkerHandle(App.class, "template", "test.xml", map, "temporary");
              DocxHandle xtd = new DocxHandle();
              documentFile = handle.processClassForTemplateLoading();
              xtd.outDocx(documentFile, new File(App.class.getResource(docxTemplate).toURI().getPath()), new FileOutputStream(App.class.getResource("temporary").getPath()+"/"+Thread.currentThread().getId()+".docx"));             
            } catch (ZipException e) {
              e.printStackTrace();
            } catch (FileNotFoundException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            } catch (URISyntaxException e) {
              e.printStackTrace();
            } catch (Exception e) {
              e.printStackTrace();
            }
            
          }
        }).start();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
